$(function(){
	$("#login").bootstrapValidator({
		/*配置校验不同状态下显示的图标*/
		 feedbackIcons: {  
		 	/*校验成功*/
            valid: 'glyphicon glyphicon-ok',  
            /*校验失败*/
            invalid: 'glyphicon glyphicon-remove',  
            /*正在校验*/
            validating: 'glyphicon glyphicon-refresh'  
        },
        fields:{
        	/*对应表单的name*/
        	username:{
        		/*校验方式*/
        		validators:{
        			/*不能为空*/
        			notEmpty:{
        				message:"用户名不能为空"
        			},
        			callback: {
        				message: "用户名不存在"
        			}
        		}
        	},
        	password:{
        		/*校验方式*/
        		validators:{
        			/*不能为空*/
        			notEmpty:{
        				message:"密码不能为空"
        			},
        			stringLength: {
        				min: 6,
        				max: 18,
        				message: "密码长度必须在6-18字符"
        			},
        			regexp: {
        				regexp: /^[a-zA-Z0-9_]+$/,
        				message: "用户名只能包含字母、数字和下划线"
        			},
        			callback: {
        				message: "密码错误"
        			}
        		}
        	}

        }
	}).on("success.form.bv",function(e){
		e.preventDefault();
		// 后台校验
		var $form = $(e.target);
		$.ajax({
			url:"/employee/employeeLogin",
			type:"post",
			data: $form.serialize(),
			dataType:"json",
			success: function(e){
				if(e.error){
					if(e.error == 1000){
						// ;
						$form.data("bootstrapValidator").updateStatus("username","INVALID","callback");
						console.log("用户名不存在")
					}else if(e.error == 1001){
						$form.data("bootstrapValidator").updateStatus("password","INVALID","callback");
						console.log("用户密码错误");
					}
				}
				else if(e.success){
					location.href  = "/admin1/"
				}
			}
		})
	})



});